var areaData = address;
var $form;
var form;
var $;
layui.config({
    base: "../../js/"
}).use(['form', 'layer', 'upload', 'laydate'], function () {
    form = layui.form();
    var layer = parent.layer === undefined ? layui.layer : parent.layer;
    $ = layui.jquery;
    $form = $('form');
    laydate = layui.laydate;


    $('#resetBtn').click(function(){
        window.location.reload();
    });

   /* upload({
        url: "../../json/userface.json",
        success: function (res) {
            var num = parseInt(4 * Math.random());  //生成0-4的随机数
            //随机显示一个头像信息
            userFace.src = res.data[num].src;
            window.sessionStorage.setItem('userFace', res.data[num].src);
        }
    });

    //判断是否修改过头像，如果修改过则显示修改后的头像，否则显示默认头像
   if (window.sessionStorage.getItem('userFace')) {
        $("#userFace").attr("src", window.sessionStorage.getItem('userFace'));
    } else {
        $("#userFace").attr("src", "../../images/face.jpg");
    }*/
   layui.upload({
    url: '/oss/ossImgUpload?filedir='+filedir,
        before: function(input){
        //返回的参数item，即为当前的input DOM对象
        console.log('文件上传中');
    },
    success: function(res){
        console.log('上传完毕');
        console.log(">>>>>>>>>>>>>>>"+JSON.stringify(res));
        $("#actorFace").attr("src",res.link);
        $("#faceurl").val(res.link);
    }
});
    //提交个人资料
    form.on("submit(submitPrize)", function (data) {
        // var index = layer.msg('提交中，请稍候',{icon: 16,time:false,shade:0.8});
        //将填写的用户信息存到session以便下次调取
        if(!checkImgUpload()) return false;
        var data = $("#prizeAddForm").serialize();

        $.ajax({
            cache: false,
            type: 'POST',
            url: "/prize/addPrize",
            dataType: "json",
            data: data,
            async: false,
            success: function (data) {
                if (data.errType === "0000") {
                    top.layer.alert("保存成功", {icon: 1});
                    setTimeout(function () {
                        var pIndex = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                        parent.layer.close(pIndex); //再执行关闭
                        parent.window.location.reload();
                    },1000)

                } else {
                    top.layer.alert("保存异常,请重试", {icon: 0});
                }
            },
            error: function () {
                top.layer.alert("发生异常,请重试", {icon: 2});
            }
        })
        return false;
    })


})

